//
//  ZZCWithdrawController.m
//  ZZC-Finance
//
//  Created by mac on 2017/5/23.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "ZZCWithdrawController.h"
#import "ZZCWithdrawOneController.h"
#import "ZZCOwnPropertyController.h"
#import "ZZCMeUbiViewController.h"

@interface ZZCWithdrawController ()
@property (weak, nonatomic) IBOutlet UITextField *payeeNameFld;
@property (weak, nonatomic) IBOutlet UITextField *bankCardNumFld;
@property (weak, nonatomic) IBOutlet UITextField *PhoneFld;
@property (weak, nonatomic) IBOutlet UITextField *needCashFld;
@property (weak, nonatomic) IBOutlet UILabel *cashMoneyLabel;

@end

@implementation ZZCWithdrawController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"U币提现";
    self.cashMoneyLabel.text = self.moneyCount;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}

//确认
- (IBAction)confirmClick {
//    timestamp	是	int(10)	时间戳
//    sign	是	string	签名
//    token	是	string	用户token
//    username	是	string	姓名
//    bank_card	是	string	银行卡号
//    phone	是	string	手机号
//    money	是	float	提现金额
    NSString * token = ZZCNSUserDefaults(@"token");
    NSDictionary *dict = @{@"token":token,
                           @"username":self.payeeNameFld.text,
                           @"bank_card":self.bankCardNumFld.text,
                           @"phone":self.PhoneFld.text,
                           @"money":self.needCashFld.text
                           };
    NSString *sign = [ZZCRequest getSignWithDict:dict];
    sign = [NSString md5:[sign lowercaseString]];
    NSDictionary *param = @{@"timestamp":[NSString timeStr],@"sign":sign,
                            @"token":token,
                            @"username":self.payeeNameFld.text,
                            @"bank_card":self.bankCardNumFld.text,
                            @"phone":self.PhoneFld.text,
                            @"money":self.needCashFld.text
                            };
    NSLog(@"%@",param);
    [[ZZCRequest sharedNetworkTools] POST:ZZCURL_API_WITHDRAW_DOAPPLY parameters:param finished:^(id  _Nullable responseObject, NSError * _Nullable error) {
        if (error) {
            ZZCLog(@"失败-%@",error);
        }else {
            ZZCLog(@"成功-%@",responseObject);
            [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
            if ([responseObject[@"msg"] isEqual:@"400"]) {
                return;
            } else if([responseObject[@"msg"] isEqual:@"200"]){
                for (UIViewController *controller in self.navigationController.viewControllers) {
                    if ([controller isKindOfClass:[ZZCOwnPropertyController class]]||
                        [controller isKindOfClass:[ZZCMeUbiViewController class]]) {
                        [self.navigationController popToViewController:controller animated:YES];
                    }
                }
            }
        }
    }];

}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;
{
    if (textField == self.PhoneFld) {
        //用来做长度限制；
        if (range.location>=11) {
            return NO;
        }
    }
    return YES;
    
}

@end
